package com.ruoyi.web.controller.message;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.message.service.IMailFromUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;

@Controller
@RequestMapping("/mail")
public class MailController extends BaseController {

    private  final Logger log = LoggerFactory.getLogger(MailController.class);

    private String prefix = "message/mail";

    @Autowired
    private IMailFromUserService mailFromUserService;

    /**
     * 新增邮箱发件人账号
     */
    @GetMapping("/send/{uuid}")
    public String send(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        mmap.put("uuid", uuid);
        return prefix + "/send";
    }


    /**
     * 新增保存邮箱发件人账号
     */
    //@RequiresPermissions("mail:send")
    @Log(title = "发送邮件", businessType = BusinessType.OTHER)
    @PostMapping("/send")
    @ResponseBody
    public AjaxResult send(String uuid, String mailTo,String subject, String context, String files){
        int resultcode = 0;
        try{
            mailFromUserService.sendMail(uuid, mailTo, subject, context, files);




            resultcode = 1;
        }catch (Exception e){
            log.info(e.toString());
        }
        return toAjax(resultcode);
    }

}
